const {HomeInfo,Avater} = require("../model");
const {setR,getR,delR,caseTime} = require('./redisServe')
exports.getMeun = async (originalUrl)=>{
   
    const Cresult  = await getR(0,originalUrl);

     if(Cresult){
         return JSON.parse(Cresult);
     }else{
        const result = await HomeInfo.find();
        await setR(0,originalUrl,JSON.stringify(result[0]));
        return result[0];
     } 
}


exports.upInfo = async (_id,Nav,mailto,recrod,icon)=>{
   const result = await  HomeInfo.updateOne({_id},{
        $set:{
            Nav,
            mailto,
            recrod,
            icon
        }
    })

    return result;
} 

exports.getAvater= async (originalUrl)=>{
    const Cresult = await getR(0,originalUrl);
    if(Cresult){
        return JSON.parse(Cresult);
    }else{
        const result = await Avater.find();
        await setR(0,originalUrl,JSON.stringify(result[0]));
        return result[0] 
    }
}
exports.upAvatar = async (_id,name,img,descript)=>{
    const result = await Avater.updateOne({_id},{
        $set:{
            name,
            img,
            descript
        }
    })
    if(result){
        return true
    }else{
        return "修改失败"
    } 
}

exports.addAvater = async (obj)=>{
    const result = await Avater.create(obj);
    return result;
}